﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;

public partial class member : OTS.MemberPage   //System.Web.UI.Page   OTS.MemberPage 
{
    protected string strConent;
    protected string strOrders;
    protected string strShouCang;
    OTS.BLL.CartBLL BLL = new OTS.BLL.CartBLL();
    OTS.BLL.FavoriteBLL FavBll = new OTS.BLL.FavoriteBLL();
    OTS.BLL.SaleOrderBLL SalesBLL = new OTS.BLL.SaleOrderBLL();
    OTS.Model.custom custom = new OTS.Model.custom();
    List<OTS.Model.saleOrder> sOrderList = new List<OTS.Model.saleOrder>();
    DataTable dt = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!TestLogin(HttpContext.Current))
        {
            Response.Redirect("index.aspx");
            return;
        }
        if (!Page.IsPostBack)
        {
            FillContent();
            BindOrders();
            BindShouCang();

            custom = GetCustom(HttpContext.Current);
            this.lblUser.Text = custom.cusLoginName;
        }
    }
    private void FillContent()
    {
        custom = GetCustom(HttpContext.Current);
        dt = BLL.GetListByCartCusID(custom.cusID);
        StringBuilder str = new StringBuilder();

        if (dt.Rows.Count > 0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                str.Append("<tr cartID=\"" + dr["cartID"].ToString() + "\">");
                str.Append(" <td>");
                str.Append("    <a style=\"border: 0 none;\" target=\"_blank\" href=\"product.aspx?proID=" + dr["proID"].ToString() + " \">");
                if (dr["bigImg_pic"].ToString()=="")
                {
                    str.Append("<img height='50' width='33' src='img/yes_picture.gif' />");
                }
                else
                {
                    str.Append("<img height='50' width='33' src='" + PictureProcessing.ImgPathToThumbURL(dr["bigImg_pic"].ToString()) + "' />");
                }
                str.Append("</a>");
                str.Append(" </td>");
                str.Append(" <td style=\"text-align: left;\" >");
                str.Append("    <a style=\"border: 0 none;\" target=\"_blank\" href=\"product.aspx?proID=" + dr["proID"].ToString() + " \">");
                str.Append(dr["title"].ToString());
                str.Append("    </a>");
                str.Append(" </td>");
                str.Append(" <td>");
                str.Append(dr["sizeName"].ToString());
                str.Append(" </td>");
                str.Append(" <td>");
                str.Append(dr["col_color"].ToString());
                str.Append(" </td>");
                str.Append(" <td class=\"mktprice1\">");
                str.Append(dr["wholeSalePrice"].ToString());
                str.Append(" </td>");
                str.Append(" <td>");
                str.Append(dr["retailPrice"].ToString());
                str.Append(" </td>");
                str.Append(" <td ><div class=\"Numinput\">");
                str.Append("    <label>" + dr["pCount"].ToString() + "</label> ");
                str.Append("        </div>");
                str.Append(" </td>");
                str.Append("</tr>");
            }
            DataTable dTable = BLL.GetCartProTotle(1);
            str.Append("<tr>");
            str.Append("<td colspan=\"7\">");
            str.Append("<div style=\"text-align: right; color: #999;\">");
            str.AppendFormat("您的购物车中有 <strong class=\"ftx\">" + dTable.Rows[0]["totle"].ToString() + "</strong> 件商品");
            str.Append("</div>");
            str.Append("</td>");
            str.Append("</tr>");
        }
        else
        {
            str.Append("<div id=\"cart-none-msg\">");
            str.Append("<div class=\"note\" style=\"border-width: 1px;\">");
            str.Append("<h3>购物车目前没有加入任何商品!</h3>");
            str.Append("</div>");
            str.Append("</div>");
        }
        strConent = str.ToString();
    }

    protected void BindOrders() {
        string status = "";
        custom = GetCustom(HttpContext.Current);
        sOrderList = SalesBLL.GetByCustomID(custom.cusID);
        StringBuilder strSb = new StringBuilder();

        if (sOrderList!=null)
        {
            for (int i = 0; i < sOrderList.Count; i++)
            {
                sOrderList[i].list = SalesBLL.GetDetail(sOrderList[i].orderID);
                strSb.Append("<tr>");
                strSb.AppendFormat("<td>" + sOrderList[i].orderNO + "</td>");
                strSb.Append("<td class=\"img-list\">");

                for (int j = 0; j < sOrderList[i].list.Count; j++)
                {
                    if (sOrderList[i].list.Count >= 2)
                    {
                        strSb.Append("<div class=\"divstyle\">");
                        strSb.AppendFormat("<a target=\"_blank\" href=\"product.aspx?proID=" + sOrderList[i].list[j].proID + "\">");
                        if (sOrderList[i].list[j].bigImg_pic=="")
                        {
                            strSb.AppendFormat("<img src=\"img/yes_picture.gif\" alt=\"" + sOrderList[i].list[j].title + sOrderList[i].list[j].proNO + "\" />");
                        }
                        else
                        {
                            strSb.AppendFormat("<img src=\"" + PictureProcessing.ImgPathToThumbURL(sOrderList[i].list[j].bigImg_pic) + "\" alt=\"" + sOrderList[i].list[j].title + sOrderList[i].list[j].proNO + "\" />");
                        }
                        strSb.Append("</a>");
                        strSb.Append("</div>");
                    }
                    else
                    {
                        strSb.Append("<div>");
                        strSb.AppendFormat("<a target=\"_blank\" href=\"product.aspx?proID=" + sOrderList[i].list[j].proID + "\">");
                        if (sOrderList[i].list[j].bigImg_pic == "")
                        {
                            strSb.AppendFormat("<img src=\"img/yes_picture.gif\" alt=\"" + sOrderList[i].list[j].title + sOrderList[i].list[j].proNO + "\" />");
                        }
                        else
                        {
                            strSb.AppendFormat("<img src=\"" + PictureProcessing.ImgPathToThumbURL(sOrderList[i].list[j].bigImg_pic) + "\" alt=\"" + sOrderList[i].list[j].title + sOrderList[i].list[j].proNO + "\" />");
                        }
                        strSb.Append("</a>");
                        strSb.Append("</div>");
                    }
                }
                strSb.Append("</td>");
                strSb.AppendFormat("<td>" + sOrderList[i].consignee + "</td>");
                strSb.AppendFormat("<td>" + sOrderList[i].totalMoney + "</td>");
                strSb.Append("<td>");
                strSb.AppendFormat("<span style=\"color: #999;\">" + sOrderList[i].addTime + "</span>");
                strSb.Append("</td>");
                strSb.Append("<td style=\"background: none repeat scroll 0 0 #FFFFCC;\">");
                if (sOrderList[0].status == 0)
                {
                    status = "未付款";
                }
                else if (sOrderList[0].status == 1)
                {
                    status = "已付款";
                }
                else if (sOrderList[0].status == 2)
                {
                    status = "已发货";
                }
                strSb.AppendFormat("<strong style=\"color: #FF6600;\">" + status + "</strong>");
                strSb.Append("</td>");
                strSb.Append("</tr>");
            }

            dt = SalesBLL.GetTongJi(custom.cusID);
            if (dt.Rows.Count > 0)
            {
                this.lblSalesY.Text = dt.Rows[0]["salesY"].ToString();
                this.lblSalesN.Text = dt.Rows[0]["salesN"].ToString();
                this.lblSalesTotle.Text = dt.Rows[0]["totle"].ToString();
            }
            this.lblSalesY.Text = "0";
            this.lblSalesN.Text = "0";
            this.lblSalesTotle.Text = "0";
        }
        else
        {
            this.panelOrders.Visible = false;
            strSb.Append("<div style=\"border-top: 1px solid #E5E5E5; width: 100%; float: left;color:#7E7E7E;\">");           
            strSb.Append("<p style=\"padding-top:5px;margin-left:10px;\">暂无订单</p>");
            strSb.Append("</div>");
        }
        strOrders = strSb.ToString();
    }

    protected void BindShouCang()
    {
        custom = GetCustom(HttpContext.Current);
        dt = FavBll.GetListByFavCusID(custom.cusID);
        StringBuilder sb = new StringBuilder();

        if (dt.Rows.Count>0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                sb.Append("<td>");
                sb.AppendFormat("<a title=\"" + dr["title"].ToString() + dr["proNO"].ToString() + "\" href=\"product.aspx?proID=" + dr["proID"].ToString() + "\" style=\"display: block; width: 188px; height: 282px;\">");
                string imgUrl = dr["bigImg_pic"].ToString();
                if (imgUrl=="")
                {
                    sb.AppendFormat("<img  height='282' width='188' alt=\"" + dr["title"].ToString() + dr["proNO"].ToString() + "\" src=\"img/yes_picture.gif\" />");
                }
                else
                {
                    string strUrl = imgUrl.Replace(@"\", "/");
                    string strUrls = strUrl.Replace(@"~", ".");
                    sb.AppendFormat("<img  height='282' width='188' alt=\"" + dr["title"].ToString() + dr["proNO"].ToString() + "\" src=\"" + strUrls + "\" />");
                }
                sb.Append("</a><br />");
                sb.AppendFormat("<a title=\"" + dr["title"].ToString() + dr["proNO"].ToString() + "\" href=\"product.aspx?proID=" + dr["proID"].ToString() + "\">" + dr["title"].ToString() + dr["proNO"].ToString() + "</a><br />");
                sb.AppendFormat("<span class=\"point\">￥" + dr["retailPrice"].ToString() + "</span>");
                sb.Append("</td>");
            }
        }
        else
        {
            sb.Append("<td colspan=\"3\" stytle=\"color:#7E7E7E;\">暂无收藏</td>");
        }
        strShouCang = sb.ToString();
    }
}
